#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qgsmapcanvas.h>  // 添加QgsMapCanvas头文件
#include <qgspointxy.h>
#include <QMouseEvent>
#include <QPoint>
#include <QCursor>

#include <qgsvectorlayer.h>
#include <qgsfield.h>
#include <qgspoint.h>
#include <qgsfeature.h>
#include <qgsgeometry.h>
#include <qgslinestring.h>   // 用于 QgsLineString
#include <qgslinesymbol.h>   // 添加此头文件来访问 QgsLineSymbol
#include <qgssinglesymbolrenderer.h> // 渲染器
#include <qgsmarkersymbol.h>// 用于设置点的符号样式
#include <qgssymbol.h>
#include <qgssinglesymbolrenderer.h>
//#include <qgsrenderer.h>// qgsrenderercategory.h>
#include <qgscategorizedsymbolrenderer.h>// qgscategorizedsymbolrendererv2.h>
#include <qgscategorizedsymbolrendererwidget.h>
#include <qgsrulebasedrenderer.h>
#include <qgsrenderer.h>

#include <qgsfeaturerequest.h>
#include <qgseditformconfig.h>
#include <qgslabeling.h>
#include <qgstextformat.h>
//#include <QgsPalLayerSettings.h>

// 引入 QgsLabelRenderer 头文件

#include <qgslayertreeview.h>
#include <qgslayertree.h>
#include <qgslayertreemodel.h>
#include <QSplitter>
#include <QStyledItemDelegate>
#include <QPainter>
#include <QCheckBox>
#include <QModelIndex>
#include <QStyleOptionButton>
#include <QStyleOptionButton>
#include <LayerVisibilityDelegate.h>
#include <qgsmaplayer.h>  // 用于引用QgsLayer
#include <qgslayertreenode.h>
#include <qgslayertreelayer.h>
#include <qtreewidget.h>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit  MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_panButton_clicked();

    void on_openButton_clicked();
    void on_ZoomInButton_clicked();
    void on_ZoomOutButton_clicked();

    void on_AddShpButton_clicked();

    void on_AddMifButton_clicked();

    void on_OpenQgzButton_clicked();

    void on_AddMbtButton_clicked();

    void on_DrawPLButton_clicked();

protected:
    // 鼠标移动事件
    bool eventFilter(QObject *watched, QEvent *event) override;
    //void mousePressEvent(QMouseEvent *event) override;

protected slots:
    void onItemClicked(QTreeWidgetItem *item, int column);
    void onItemChanged(QTreeWidgetItem *item, int column);
private:
    // 辅助函数：将屏幕坐标转换为地图坐标
    //QgsPointXY getCoordinateFromScreen(const QPoint &screenPos);
    QString degreesToDMS(double degrees);
    void modifyPointSymbol(QgsVectorLayer* layer, const QString& fieldName, int featureId);
    void DrawPoints(QList<QgsPoint> Pointlist);
    void DrawLines(QList<QgsPoint> Pointlist);
    void DrawLine(QgsVectorLayer* lineLayer,QgsFields fields,QList<QgsPoint> Pointlist,int i);
    void PrintVectorLayerData(QgsVectorLayer* VecLayer);
private:
    Ui::MainWindow *ui;
    QgsMapCanvas *canvas;  // 在此声明canvas作为成员变量
    QgsMapSettings mapSettings;
    QgsCoordinateTransform coordTransform;
    QList<QgsMapLayer*> Alllayers;
    QgsProject *project;
    QTreeWidget *MytreeWidget;
    void movePointById(QgsVectorLayer *pointLayer, int pointId, double offsetX, double offsetY);
    void DispPointLabelById(QgsVectorLayer *pointLayer, int pointId, QString label);
    void enableLabeling(QgsVectorLayer *pointLayer);
    void onLayerVisibilityChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
    void toggleLayerVisibility(QgsLayerTreeView *layerTreeView, QgsLayerTreeModel *layerTreeModel);
    void setupLayerTreeView(QgsProject *project);
    void AddLayerTreeView(QgsRasterLayer *newlayer);
};


#endif // MAINWINDOW_H
